package com.xb.loan.util.qrtz.listener;


import com.xb.loan.util.qrtz.common.Constants;
import com.xb.loan.util.qrtz.common.bean.TaskEntity;
import com.xb.loan.util.qrtz.task.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 *监听任务执行  持久化任务
 * @author hyd
 */
public class TaskStoreListener implements TaskListener, Constants {
	protected Logger logger = LoggerFactory.getLogger(getClass());

	public void taskCreate(Task task) {
		if (task.getTaskStoreSupport().taskIsExists(task))
			throw task_insert_error;
		task.getTaskStoreSupport().addTaskEntiry(task);
	}

	public void taskToBeExecuted(Task task) {
		TaskEntity taskEntity = task.getTaskStoreSupport().getTaskEntity(task);
		if (taskEntity == null || Status.COMPLETE.toString().equals(taskEntity.getTask_status()))
			throw task_operate_error;
		task.getTaskStoreSupport().updateTaskEntiry(task, false);
	}

	public void taskExecutionVetoed(Task task) {
	}

	public void taskWasExecuted(Task task) {
		task.getTaskStoreSupport().updateTaskEntiry(task, true);
	}

}
